package com.yc.demo;

import com.yc.demo.service.impl.HelloService;
import com.yc.demo.util.SpringContextUtil;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.*;

import lombok.extern.slf4j.Slf4j;


/**
 * <p>启动类</p>
 *
 * @author YuanChilde
 * @date 2019-05-07 13:12
 * @version 1.0
 * Modification History:
 * Date    Author      Version     Description
 * -----------------------------------------------------------------
 * 2019-05-07 13:12    YuanChilde     1.0        新增
 */
@Slf4j
@EnableAutoConfiguration
@ComponentScan(basePackages = "com.yc.demo")
@MapperScan("com.yc.demo.dao*")
@EnableTransactionManagement
public class StartupApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(StartupApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        String serverIp = InetAddress.getLocalHost().getHostAddress();
        log.info("app started. http://" + serverIp + ":" + SpringContextUtil.getPort() + SpringContextUtil.getContentPath());
    }

    @Bean(initMethod = "init",destroyMethod = "")
    public HelloService createHelloService(){
        return new HelloService();
    }
}
